package org.niugang.security.log.web;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.niugang.security.common.vo.PageResult;
import org.niugang.security.log.pojo.LogDO;
import org.niugang.security.log.service.LogService;
import org.niugang.security.users.vo.UserVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import java.util.List;

/**
 * @author Created by niugang on 2019/5/24/20:07
 */
@RestController
@RequestMapping("logs")
@Api(value = "日志接口", tags = {"日志接口"})
public class LogController {


    @Autowired
    private LogService logService;


    @GetMapping
    @ApiOperation(value = "查询日志列表",notes = "查询日志列表")
    public ResponseEntity<PageResult<LogDO>> list(@Min(1) @RequestParam(defaultValue = "1") Integer pageNo, @Max(100) @Min(5) @RequestParam(defaultValue = "10") Integer pageSize){
        Page<LogDO> page=logService.findByPage(pageNo,pageSize);
        PageResult<LogDO> result = new PageResult<>();
        result.setTotal(page.getTotalElements());
        result.setData(page.getContent());
        result.setTotalPage(page.getTotalPages());
        result.setPageNO(pageNo);
        result.setPageSize(pageSize);
        return ResponseEntity.ok(result);
    }

}
